package com.origin.onlinesys.service.modules.interviewsys.impl;

import com.origin.onlinesys.common.services.BaseService;
import com.origin.onlinesys.domain.modules.interviewsys.Education;
import com.origin.onlinesys.persistence.modules.interviewsys.EducationMapper;
import com.origin.onlinesys.service.modules.interviewsys.IEducationService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2015/1/22 0022.
 */
@Service
public class EducationServiceImpl extends BaseService<Education> implements IEducationService{
    /**
     * 插入学历数据
     * @param edu 学历对象
     * @return
     */
    public Education insertEdu(Education edu){
        String id = this.checkHave(edu.getName());
        edu.setState("1");
        if(id == null){
            edu.setId(this.save(edu)+"");
        }else{
            edu.setId(id);
            this.updateEdu(edu);
        }
        return edu;
    }

    /**
     * 删除学历数据
     * @param id
     * @return
     */
    public int deleteEdu(String id){
        Education edu = new Education();
        edu.setId(id);
        edu.setState("2");
        return update(edu);
    }

    /**
     * 修改学历数据
     * @param edu 学历对象
     * @return
     */
    public int updateEdu(Education edu){
        return this.update(edu);
    }

    /**
     * 查询所有
     * @return
     */
    public List<Education> selectAllEdu(){
        return this.queryAll();
    }

    /**
     * 根据状态查询数据
     * @param state 学历对象
     * @return
     */
    public List<Education> selectByState(String state){
        Education edu = new Education();
        edu.setState(state);
        return this.queryByWhere(edu);
    }

    public String checkHave(String name) {
        return ((EducationMapper)mapper).checkHave(name);
    }
}
